import peewee


def of_null(data, name="参数"):
    if not data:
        raise Exception(f"LJ - [{name}]不能为空...")

    return data


def v_of_null(obj, name):
    return of_null(v(obj, name), name)


def v(obj, name):
    if not obj:
        return
    if isinstance(obj, dict):
        return obj.get(name)
    if isinstance(obj, type) or isinstance(obj, peewee.Model):
        return getattr(obj, name)
